package com.hhp.cloud.shop.admin.controller;

import java.util.Arrays;


import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hhp.cloud.shop.admin.pojo.entity.UserRoleEntity;
import com.hhp.cloud.shop.admin.service.UserRoleService;

import com.hhp.cloud.shop.common.core.result.R;



/**
 * 用户和角色关联表
 *
 * @author hhp
 * @email 2437579794@qq.com
 * @date 2021-11-23 10:25:32
 */
@RestController
@RequestMapping("/api/v1/admin/userRole")
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;


    /**
     * 信息
     */
    @ApiOperation(value = "用户角色详情")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/{userId}")
    public R info(@PathVariable("userId") Integer userId){
        return R.ok().setData(userRoleService.getById(userId));
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增用户角色")
    @PostMapping
    public R save(@RequestBody UserRoleEntity userRole){
		userRoleService.save(userRole);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改用户角色")
    @PutMapping
    public R update(@RequestBody UserRoleEntity userRole){
		userRoleService.updateById(userRole);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除用户角色")
    @DeleteMapping
    public R delete(@RequestBody Integer[] userIds){
		userRoleService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
